<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;
use yii\bootstrap\Modal;
use backend\models\File;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\FileSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

conquer\gii\GiiAsset::register($this);

$this->title = '上传文件列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="file-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
    <?= Html::a('添加新闻包', ['create'], [
        'class' => 'btn btn-success show-modal',
        'data-target' => '#modal_view',
        'data-header' => 'Create File',
    ]); ?>
    </p>

    <?= Modal::widget([
        'id' => 'modal_view',
        'size' => Modal::SIZE_LARGE,
        'clientEvents' => [
            'hidden.bs.modal'=>'function (e) {
                $(this).find(".modal-body").html("");
            }',
        ],
    ]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            'id',
            'name',

            'file_path',
            'operate',
            [
                'attribute'=>'status',
                'value'=>function($model, $key, $index, $grid) {
                    return \backend\models\File::$statusArray[$model->status];
                },
                'filter'=>\backend\models\File::$statusArray,
            ],
//            'created_at:datetime',
//             'updated_at:datetime',

            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view} {update} {delete} {reset-miss}',
                'buttons' => [
                    'view' => function ($url, $model, $key) {
                        $options = array_merge([
                            'title' => Yii::t('yii', 'View'),
                            'aria-label' => Yii::t('yii', 'View'),
                            'class'=>'show-modal',
                            'data-target' => '#modal_view', 
                            'data-header' => Yii::t('yii', 'View') . ' ' . 'Files',
                        ]);
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
                    },
                    'update' => function ($url, $model, $key) {
                        $options = array_merge([
                            'title' => Yii::t('yii', 'Update'),
                            'aria-label' => Yii::t('yii', 'Update'),
                            'class'=>'show-modal',
                            'data-target' => '#modal_view', 
                            'data-header' => Yii::t('yii', 'Update') . ' ' . 'Files',
                        ]);
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);
                    },
                    'reset-miss' => function($url, $model, $key) {
                        if($model->miss!=File::MISSING) return '';
                        $options = array_merge([
                            'title' => '重置',
                            'aria-label' => '重置',
                            'data-confirm' => '确认重置吗?',
                            'data-method' => 'post',
                            'data-pjax' => '0',
                        ], []);

                        return Html::a('<span class="glyphicon glyphicon-check"></span>', $url, $options);

                    }
                ],
            ],
        ],
    ]); ?>

</div>